package com.qch.rabbitmq.demo;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @Author qch
 * @Date 2021/5/14
 */
public class ShenzhenConsumer {
    public static void main(String[] args)throws  Exception {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setUri("amqp://root:123456@192.168.142.135:5672/%2f");
        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();
        String queue = channel.queueDeclare().getQueue();
        channel.exchangeDeclare("ex.topic",BuiltinExchangeType.TOPIC,true,false,null);
        channel.queueBind(queue,"ex.topic","shenzhen.emp-online.*");
        channel.basicConsume(queue,(consumerTag,message)->{
            System.out.println(new String(message.getBody(),"utf-8"));
        },(consumerTag)->{});
    }
}
